package com.openbravo.pos.reports;

import com.openbravo.basic.BasicException;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.QBFCompareEnum;
import com.openbravo.data.loader.SerializerWrite;
import com.openbravo.data.loader.SerializerWriteBasic;
import com.openbravo.format.Formats;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class JParamsText extends JPanel
  implements ReportEditorCreator
{
  private Datas datasvalue;
  private Formats formatsvalue;
  private QBFCompareEnum comparevalue;
  private JLabel lblField;
  private JTextField txtField;

  public JParamsText()
  {
    initComponents();
    setLabel(AppLocal.getIntString("label.value"));
    setType(Formats.STRING);
  }

  public JParamsText(String paramString)
  {
    initComponents();
    setLabel(paramString);
    setType(Formats.STRING);
  }

  public JParamsText(String paramString, Formats paramFormats)
  {
    initComponents();
    setLabel(paramString);
    setType(paramFormats);
  }

  public JParamsText(String paramString, Formats paramFormats, Datas paramDatas)
  {
    initComponents();
    setLabel(paramString);
    setType(paramFormats, paramDatas);
  }

  public void setLabel(String paramString)
  {
    this.lblField.setText(paramString);
  }

  public void setType(Formats paramFormats, Datas paramDatas)
  {
    this.formatsvalue = paramFormats;
    this.datasvalue = paramDatas;
    setDefaultCompare();
  }

  public void setType(Formats paramFormats)
  {
    if (Formats.INT == paramFormats)
      setType(paramFormats, Datas.INT);
    else if ((Formats.DOUBLE == paramFormats) || (Formats.CURRENCY == paramFormats) || (Formats.PERCENT == paramFormats))
      setType(paramFormats, Datas.DOUBLE);
    else if ((Formats.DATE == paramFormats) || (Formats.TIME == paramFormats) || (Formats.TIMESTAMP == paramFormats))
      setType(paramFormats, Datas.TIMESTAMP);
    else if (Formats.BOOLEAN == paramFormats)
      setType(paramFormats, Datas.BOOLEAN);
    else
      setType(paramFormats, Datas.STRING);
  }

  public void setCompare(QBFCompareEnum paramQBFCompareEnum)
  {
    this.comparevalue = paramQBFCompareEnum;
  }

  private void setDefaultCompare()
  {
    if (Formats.INT == this.formatsvalue)
      this.comparevalue = QBFCompareEnum.COMP_LESSOREQUALS;
    else if ((Formats.DOUBLE == this.formatsvalue) || (Formats.CURRENCY == this.formatsvalue) || (Formats.PERCENT == this.formatsvalue))
      this.comparevalue = QBFCompareEnum.COMP_LESSOREQUALS;
    else if ((Formats.DATE == this.formatsvalue) || (Formats.TIME == this.formatsvalue) || (Formats.TIMESTAMP == this.formatsvalue))
      this.comparevalue = QBFCompareEnum.COMP_GREATEROREQUALS;
    else if (Formats.BOOLEAN == this.formatsvalue)
      this.comparevalue = QBFCompareEnum.COMP_EQUALS;
    else
      this.comparevalue = QBFCompareEnum.COMP_RE;
  }

  public void init(AppView paramAppView)
  {
  }

  public void activate()
    throws BasicException
  {
    this.txtField.setText(null);
  }

  public SerializerWrite getSerializerWrite()
  {
    return new SerializerWriteBasic(new Datas[] { Datas.OBJECT, this.datasvalue });
  }

  public Component getComponent()
  {
    return this;
  }

  public Object createValue()
    throws BasicException
  {
    Object localObject = this.formatsvalue.parseValue(this.txtField.getText());
    this.txtField.setText(this.formatsvalue.formatValue(localObject));
    if (localObject == null)
      return new Object[] { QBFCompareEnum.COMP_NONE, null };
    return new Object[] { this.comparevalue, localObject };
  }

  private void initComponents()
  {
    this.lblField = new JLabel();
    this.txtField = new JTextField();
    setPreferredSize(new Dimension(0, 30));
    setLayout(null);
    this.lblField.setText("***");
    add(this.lblField);
    this.lblField.setBounds(20, 10, 120, 14);
    add(this.txtField);
    this.txtField.setBounds(140, 10, 200, 18);
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.reports.JParamsText
 * JD-Core Version:    0.6.0
 */